LGF_ShiftRegister (FB / 4.0.0)

Overview

Author: Siemens Digital Industry Support

Short description

The Function represents a shift register for any kind of Datatype (using variant).
It is possible to shift the elements in the array at bufferRegister to the left (index array[n]:=array[n+1]) or right (index array[n]:=array[n-1]).
It could be used for material tracking trough a machine or a process, e.g. for a rotary indexing table.


Note
As this is a real shift operation, it may cause some runtime effects while using big array sizes to move at the input bufferRegister.
Please consider that a FIFO or LIFO storage, based on indexes, could be used as well for most applications.

Block Interface

LGF_ShiftRegister (FB)
Bool  enable valid  Bool
    
Bool  shiftLeft busy  Bool
    
Bool  shiftRight error  Bool
    
UInt  shiftRange status  Word
    
Bool  reset leftShiftCount  DInt
    
Bool  clear rightShiftCount  DInt
    
Bool  fill shiftOffsetCounter  DInt
    
Variant  initialItem diagnostics  LGF_typeDiagnostics
    
Variant  bufferRegister  Variant
       
   

Input parameter

IdentifierData type Default value Description
enableBool FALSE TRUE: Enable functionality of FB
shiftLeftBool FALSE Rising edge: Elements in the array `bufferRegister` shifted left.
Elements moved from index `N` to `N - 1`.
The element at index `N = 0`is overwritten
shiftRightBool FALSE Rising edge: Elements in the array `bufferRegister` shifted right.
Elements moved from index `N` to `N + 1`.
The element at index `N = lastIndex` is overwritten
shiftRangeUInt 1 Number of places to be shifted in the `bufferRegister` input array
resetBool FALSE Initializing the buffer (reset the index and the counter)
clearBool FALSE Clear buffer elements in `bufferRegister` with `initalItem`
fillBool FALSE Overwrite buffer elements after shift operation.
* `shiftLeft` - the most right element/s
* `shiftRight` - the most left element/s
overwritten by `initalItem`.
initialItemVariant --- Value with which the ARRAY of the buffer is initialized
(usually: `0` / default value)

Output parameter

IdentifierData type Description
validBool TRUE: Valid set of output values available at the FB
busyBool TRUE: FB is active and new output values can be expected
errorBool FALSE: No error
TRUE: An error occurred during the execution of the FB
statusWord 16#0000-16#7FFF: Status of the FB
16#8000-16#FFFF: Error identification (see following Table)
leftShiftCountDInt Number of left shift operations since clearing
rightShiftCountDInt Number of right shift operations since clearing
shiftOffsetCounterDInt Offset of shift operations.
`rightShift` - `leftShift`
diagnosticsLGF_typeDiagnostics Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

In/Out parameter

IdentifierData type Description
bufferRegisterVariant Buffer / Register memory as ARRAY, which keeps the data.
The data in the register is shifted left or right depending on the command.

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_NO_ERROR
Status: Execution finished without errors
16#7000STATUS_NO_CURRENT_JOBS
Status: No current jobs, initial state
16#7001STATUS_FIRST_CALL
First call after incoming new job (rising edge 'enable')
16#7002STATUS_SUBSEQUENT_CALL
Status: Subsequent call during active processing without further details
16#8001ERR_BUFFER_EMPTY
Error: The buffer is empty
16#8002ERR_BUFFER_FULL
Error: The buffer is full
16#8200ERR_NO_ARRAY
Error: No array is present at the input `bufferRegister`
16#8201ERR_CLEARING_WITHOUT_INITIAL_ITEM
Error: Clearing `bufferRegister` without an `initialItem` is not possible.
16#8202ERR_FILL_WITHOUT_INITIAL_ITEM
Error: Option `fill` the buffer after shift operation without an `initialItem` is not possible.
16#8203ERR_WRONG_TYPE_INITIAL_ITEM
Error: The data type of the input `initialItem` does not correspond to the data type of the array at the InOut parameter `bufferRegister`.
16#8204ERR_BOOL_NOT_SUPPORTED
Error: Boolean variables and arrays are not supported by `MOVE_BLOCK_VARIANT`. (Use a PLC Datatype instead)
16#8401ERR_MULTIPLE_COMMANDS_DEDECTED
Error: More than one command present at the same time. Only one of the inputs `shiftLeft`, `shiftRight` or `clear` is allowed.
16#8402ERR_IN_SHIFT_RANGE
Error: The value at `shiftRange` must not exceed the maximum size of the Array at `bufferRegister`.
16#8600ERR_UNDEFINED_STATE
Error: Due to an undefined state in state machine
16#8610ERR_CLEAR_BUFFER
Error: While clearing buffer in block `MOVE_BLK_VARIANT``. Check `subFunctionStatus` code.
16#8611ERR_SHIFT_BUFFER_LEFT
Error: While shift buffer left in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8612ERR_SHIFT_BUFFER_LEFT_FILL
Error: While fill buffer after shift left in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8621ERR_SHIFT_BUFFER_RIGHT
Error: While shift buffer right in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code
16#8622ERR_SHIFT_BUFFER_RIGHT_FILL
Error: While fill buffer after shift right in block `MOVE_BLK_VARIANT` - check `subFunctionStatus` code

User defined datatype(s)

LGF_typeDiagnostics (UDT / V1.0.1)

Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

Identifier Data type Default value Description
status Word 16#0000 Status of the Block or error identification when error occurred
subfunctionStatus Word 16#0000 Status or return value of called FB's, FC's and system blocks
stateNumber DInt 0 State in the state machine of the block where the error occurred

Change log

Version & DateChange description
1.0.0Siemens Industry Online Support
03.07.2018First released version
3.0.0Simatic Systems Support
09.04.2021Refactoring and alignment to Datatype Variant
Insert documentation
4.0.0Simatic Systems Support
04.09.2024Rework to PLC Open `Enable` behavior
Add `reset` input / counter outputs
Fix Bug while filling after left shift operation
Rework to diagnostic output datatype